#pragma once

#include <QMainWindow>

#include <qvector.h>
#include <qstring.h>

#include <qlistwidget.h>
#include <qmenu.h>
#include <qpoint.h>

#include <qnetworkreply.h>
#include <qnetworkrequest.h>
#include <qfile.h>

#include "ui_upload_page.h"

class upload_page : public QMainWindow
{
	Q_OBJECT

public:
	upload_page(QWidget *parent = nullptr);
	~upload_page();

private:

	QDir* default_save_dir;
	QString default_save_dir_path = "datasets_download";

	Ui::upload_pageClass ui;

	QVector<QString>datasets_name_list;
	QVector<QString>datasets_path_list;
	QVector<QString>annotations_list;
	QVector<int>types;

	QVector<QString>cloud_dataset_name_list;

	QMenu* local_menu = nullptr;
	QMenu* cloud_menu = nullptr;

	QNetworkReply* upload_reply = nullptr;
	QNetworkReply* download_reply = nullptr;
	QNetworkReply* list_reply = nullptr;
	QNetworkReply* clear_reply = nullptr;

	QFile* download_file = nullptr;

	void upload(QString dataset_name, QString dataset_path, QString annotation);
	void download(QString dataset_name);
	void unzip_file(QString file_name, QString dst);

private slots:
	void local_doubleclicked(QListWidgetItem* item);
	void cloud_doubleclicked(QListWidgetItem* item);

	//void update_local_list();
	void update_cloud_list();

	void local_customContextMenuRequested(const QPoint pos);
	void cloud_customContextMenuRequested(const QPoint pos);

	void upload_finished();
	void download_read();
	void download_finished();

	void list_finished();

};
